package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/8/27 19:39
 */
@RestController
@RequestMapping("/admin/hospital")
@Api(tags = "医院信息")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "根据医院id查看详情")
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id")String id) {
        Hospital hospital = hospitalService.detail(id);
        return R.ok().data("hospital", hospital);
    }

    @ApiOperation(value = "分页查询医院信息")
    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable("pageNum")Integer pageNum, @PathVariable("pageSize")Integer pageSize,
                             HospitalQueryVo hospitalQueryVo) {
        // 调用service层中分页查询的方法
        Page<Hospital> page = hospitalService.getHospitalPage(pageNum, pageSize, hospitalQueryVo);
        return R.ok().data("total", page.getTotalElements()).data("list", page.getContent());
    }

    @ApiOperation(value = "根据医院id修改医院的上线状态")
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable("id")String id, @PathVariable("status")Integer status) {
        hospitalService.updateStatus(id, status);
        return R.ok();
    }
}
